<template>
  <div class="control-panel">
    <div class="control-section">
      <h3>动画控制</h3>
      <div class="control-buttons">
        <button 
          @click="$emit('play')" 
          :disabled="isPlaying"
          class="control-btn play-btn"
        >
          ▶️ 播放
        </button>
        <button 
          @click="$emit('pause')" 
          :disabled="!isPlaying"
          class="control-btn pause-btn"
        >
          ⏸️ 暂停
        </button>
        <button 
          @click="$emit('reset')"
          class="control-btn reset-btn"
        >
          🔄 重置
        </button>
      </div>
    </div>
    
    <div class="control-section">
      <h3>播放速度</h3>
      <div class="speed-control">
        <label for="speed-slider">{{ animationSpeed }}x</label>
        <input
          id="speed-slider"
          type="range"
          min="0.1"
          max="5"
          step="0.1"
          :value="animationSpeed"
          @input="handleSpeedChange"
          class="speed-slider"
        />
        <div class="speed-labels">
          <span>0.1x</span>
          <span>5x</span>
        </div>
      </div>
    </div>
    
    <div class="control-section">
      <h3>系统状态</h3>
      <div class="status-info">
        <div class="status-item">
          <span class="status-label">状态:</span>
          <span class="status-value" :class="{ playing: isPlaying, paused: !isPlaying }">
            {{ isPlaying ? '运行中' : '已暂停' }}
          </span>
        </div>
        <div class="status-item">
          <span class="status-label">行星数量:</span>
          <span class="status-value">8</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// Props
interface Props {
  isPlaying: boolean;
  animationSpeed: number;
}

const props = defineProps<Props>();



// 处理速度变化
const handleSpeedChange = (event: Event) => {
  const target = event.target as HTMLInputElement;
  const speed = parseFloat(target.value);
  emit('speed-change', speed);
};

const emit = defineEmits<{
  play: [];
  pause: [];
  reset: [];
  'speed-change': [speed: number];
}>();
</script>

<style scoped>
.control-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 20px;
  min-width: 250px;
  color: white;
  font-family: inherit;
  z-index: 1000;
}

.control-section {
  margin-bottom: 20px;
}

.control-section:last-child {
  margin-bottom: 0;
}

.control-section h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--star-gold);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.control-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.control-btn {
  flex: 1;
  min-width: 70px;
  padding: 8px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.control-btn:hover:not(:disabled) {
  background: rgba(255, 215, 0, 0.2);
  border-color: var(--star-gold);
  transform: translateY(-1px);
}

.control-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.speed-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.speed-control label {
  font-size: 14px;
  font-weight: bold;
  color: var(--star-yellow);
  text-align: center;
}

.speed-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--star-gold);
  cursor: pointer;
  transition: all 0.3s ease;
}

.speed-slider::-webkit-slider-thumb:hover {
  background: var(--star-yellow);
  transform: scale(1.2);
}

.speed-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.6);
}

.status-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.status-value {
  font-size: 12px;
  font-weight: bold;
}

.status-value.playing {
  color: #4ade80;
}

.status-value.paused {
  color: #f87171;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .control-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    top: auto;
    min-width: 200px;
  }
  
  .control-buttons {
    flex-direction: column;
  }
  
  .control-btn {
    min-width: auto;
  }
}
</style>